-- 事务
create database if not exists mydb10_transcation;
use mydb10_transcation;
create table account(
	id int primary key,
    name varchar(20),
    money double
);

-- 插入数据
insert into account values(1,'zhangsan',1000);
insert into account values(2,'lisi',2000);

-- 关闭安全更新模式
set sql_safe_updates = 0;

update account set money = 1000 where name = 'zhangsan';
update account set money = 2000 where name = 'lisi';

-- 设置MySQL的事务为手动提交（关闭自动提交）
select @@autocommit;
set autocommit = 0;-- 关闭自动提交

-- 模拟账户转账
-- 开启事务
begin;
update account set money = money - 200 where name = 'zhangsan';
update account set money = money + 200 where name = 'lisi';
-- 提交事务
commit;-- 成功结束，记录结果

-- 回滚事务-失败结束，回归到事务执行之前的状态
rollback;

select * from account;
